from django.db import models


# Create your models here.
class Student(models.Model):
    SEX_CHOICES = (
        (0, "女"),
        (1, "男")
    )
    # verbose_name 自动生成的admin后台系统中显示的字段内容
    name = models.CharField(max_length=30, verbose_name="姓名")
    # null=True 允许为空值 blank=True 允许前端转空值 （不转值）
    age = models.IntegerField(verbose_name="年龄", null=True, blank=True)
    sex = models.IntegerField(verbose_name="性别", null=True, blank=True, choices=SEX_CHOICES)
    # 当用户执行删除的操作时，实际上是修改该字段的值 从False改为True
    # 只是把这个用户隐藏起来，查询不到
    is_delete = models.BooleanField(default=False, verbose_name="逻辑删除")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    classes = models.ForeignKey("Classes", on_delete=models.SET_NULL, null=True)

    def delete(self, using=None, keep_parents=False):
        # 把 is_delete 修改为True
        self.is_delete = True
        self.save()

    def __str__(self):
        return self.name


class Classes(models.Model):
    name = models.CharField(max_length=30, verbose_name="班级名")
    slogan = models.TextField(null=True, blank=True, verbose_name="口号")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    is_delete = models.BooleanField(default=False, verbose_name="逻辑删除")

    def __str__(self):
        return self.name
